![Julialang.org](https://raw2.github.com/JuliaLang/julialang.github.com/master/images/logo.png)

</svg></div>

[julialang.org](http://julialang.org)

Jiahao Chen
Keno Fischer

{jiahao,kfischer}@csail.mit.edu

A fresh approach to technical computing

Julia bridges the two-language divide with abstractions.

Abstractions are a resource, not a nuisance.

Abstractions in Julia are not constrained by performance or the need to obscure low-level implementation.


In [1]:
using AudioIO, SIUnits, SIUnits.ShortUnits #Load some Julia packages

immutable note{T<:Real}      #A user-defined data type
    pitch::quantity(T, Hz)   #This field has units of Hz
    duration::quantity(T, s)
    timbre::Function         #This field is a function
end

#Generate a time-domain sample of a sound wave
function waveform{T<:Real}(A::note{T}; samplingrate::quantity(T, Hz)=44100.0Hz)
   Float32[A.timbre(2π*A.pitch*t) for t in 0s:1/samplingrate:A.duration]
end


Out[1]:
waveform (generic function with 1 method)

In [3]:
#AudioIO knows how to play a waveform using libportaudio
import AudioIO.play
#Now we define what it means to play a note
play(A::note)=play(waveform(A))
play(note(440.0Hz, 2.0s, x->sin(x)+0.1*sin(2x)+0.01*sin(4x)))


Out[3]:
ArrayPlayer(true,[0.0f0,0.07763475f0,0.15467185f0,0.2305274f0,0.30464435f0,0.37650433f0,0.44563764f0,0.51163095f0,0.57413256f0,0.63285464f0  …  -0.63285464f0,-0.57413256f0,-0.51163095f0,-0.44563764f0,-0.37650433f0,-0.30464435f0,-0.2305274f0,-0.15467185f0,-0.07763475f0,1.5564812f-13],1)

In [38]:
phase{T}(pitch::quantity(T, Hz), duration::quantity(T, s)) = pitch*duration
code_native(phase, (quantity(Float32, Hz), quantity(Float32, s)))


	.section	__TEXT,__text,regular,pure_instructions
Filename: In[38]
Source line: 1
	push	RBP
	mov	RBP, RSP
Source line: 1
	movabs	RAX, 4395453136
	call	RAX
	pop	RBP
	ret

Playing nice with others

Julia can call native Fortran and C libraries with minimal fuss.


In [15]:
#This calls libc's getenv() to query the SHELL environment variable
myshell = ccall((:getenv, "libc"), Ptr{Uint8}, (Ptr{Uint8},), "SHELL")


Out[15]:
Ptr{Uint8} @0x00007fff5c716c55

In [16]:
bytestring(myshell) #C string -> Julia string


Out[16]:
"/bin/bash"

Others have built upon ccall to provide further interoperability with